<?php
namespace Admin\Controller;
use Think\Controller;
class AdminUserAddController extends Controller{
    public function adminUserAdd(){
        $username = cookie('username');
        $this->assign('username',$username);
        $this->display();
    }
    public function doAdd(){
        $post = $_POST;
        $username = $post['username'];
        $password = $post['password'];
        $repassword = $post['repassword'];
        $checkAdmin = M('Admin');
        $res = $checkAdmin->where('username="'.$username.'"')->field('username')->find();
        if($res){
            $this->error("账号名称已存在！");
        }else if($password != $repassword){
            $this->error("两次密码不一致！");
        }else{
            $data['username'] = $username;
            $data['password'] = $password;
            $add = $checkAdmin->add($data);
            if($add){
                $this->success("添加成功！");
            }else{
                $this->error("添加失败！");
            }
        }
    }
}
